import {
	defineStore
} from 'pinia'

export const userStore = defineStore('user', {
	state: () => ({
		user: {},
		promo: {},
		message: 0,
		base: {
			welcome: "",
		}
		
	}),
	getters: {
		info(state) {
			return state.user;
		},
		isLogin(state) {
			return state.user.token ? true : false;
		},
		token(state) {
			return state.user?.token || "";
		},
		msg(state) {
			return state.message;
		},
		welcome(state){
			return state?.base?.welcome;
		}
	},
	actions: {
		setUser(data) {
			this.user = data;
		},
		setMsg(num) {
			this.message = num;
		},
		setPromoInfo(data) {
			this.promo.info = data;
		},
		logout() {
			this.user = {};
			this.promo = {};
			this.message = 0;
		},
		setBase(data) {
			this.base = data;
		}
	}
})


export const chatStore = defineStore('chat', {
	state: () => ({
		data: [],
	}),
	getters: {
		list(state) {
			return state.data;
		},
		len(state) {
			return state.data.length - 1
		}
	},
	actions: {
		add(d) {
			if (this.data.length >= 60) {
				this.data.shift()
			}
			this.data.push(d)
		},
		clear() {
			this.data = [];
		}

	}
})